package ystp.service;


import org.springframework.stereotype.Service;
import ystp.dao.ZhuankeyaopinMapper;
import ystp.model.Tongkeyaopin;
import ystp.model.TongkeyaopinExample;
import ystp.model.Zhuankeyaopin;
import ystp.model.ZhuankeyaopinExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ZhuankeyaopinService {

    @Resource
    ZhuankeyaopinMapper ddMapper;

    public List<Map<String, Object>> findZhuankeBiaojueByXiangmuId(String ppxiangmuId,String ppUserId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findZhuankeBiaojueByXiangmuId(ppxiangmuId,ppUserId,mmStartIndex,ppPageSize);
    }

    public List<Map<String, Object>> findZhuankeyaopinByXiangmuId(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findZhuankeyaopinByXiangmuId(ppxiangmuId,mmStartIndex,ppPageSize);
    }
    public Integer getZhuankeCount(String ppXiangmuId,String ppdrugname,String ppjiyao,String pptongguopingjia,
                                   String ppjicaiyao,String ppchuangxinyao,String ppzhuankefenzu,String ppyuxuanyijian,String ppbeizhu) {
        Object mmCount = ddMapper.countZhuankeByXiangmuId(ppXiangmuId,ppdrugname,ppjiyao,pptongguopingjia,ppjicaiyao,ppchuangxinyao,ppzhuankefenzu,ppyuxuanyijian,ppbeizhu);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public List<Map<String, Object>> findResultByXiangmuIdAndUserid(String ppxiangmuId,String ppuserid,
                                                                    String ppdrugname,String ppjiyao,String pptongguopingjia,
                                                                    String ppjicaiyao,String ppchuangxinyao,String ppzhuankefenzu,String ppyuxuanyijian,String ppbeizhu,
                                                                    int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findResultByXiangmuIdAndUserid(ppxiangmuId,ppuserid,ppdrugname,ppjiyao,pptongguopingjia,ppjicaiyao,ppchuangxinyao,ppzhuankefenzu,ppyuxuanyijian,ppbeizhu,mmStartIndex,ppPageSize);
    }

    public boolean isexistByxiangmuId(String xiangmuId){
        ZhuankeyaopinExample mmExample=new ZhuankeyaopinExample();
        ZhuankeyaopinExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.selectByExample(mmExample).size()>0;
    }

    public Zhuankeyaopin findOne(String id){
        return ddMapper.selectByPrimaryKey(id);
    }

    public List<Zhuankeyaopin> findAllByXiangmuId(String xiangmuId){
        ZhuankeyaopinExample mmExample=new ZhuankeyaopinExample();
        ZhuankeyaopinExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return ddMapper.selectByExample(mmExample);
    }


    public List<Zhuankeyaopin> findAllByXiangmuIdAndGuizebianhao(String xiangmuId,String guizebianhao){
        ZhuankeyaopinExample mmExample=new ZhuankeyaopinExample();
        ZhuankeyaopinExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId).andGuizebianhaoEqualTo(guizebianhao);
        return ddMapper.selectByExample(mmExample);
    }


    public List<Zhuankeyaopin> findAllByXiangmuIdAndJicaiyao(String xiangmuId){
        ZhuankeyaopinExample mmExample=new ZhuankeyaopinExample();
        ZhuankeyaopinExample.Criteria criteria =mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId).andJicaiyaoEqualTo("是");
        return ddMapper.selectByExample(mmExample);
    }


    public List<Zhuankeyaopin> findAllByXiangmuIdAndChuangxinyao(String xiangmuId){
        ZhuankeyaopinExample mmExample=new ZhuankeyaopinExample();
        ZhuankeyaopinExample.Criteria criteria =mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId).andChuanxinyaoEqualTo("是");
        return ddMapper.selectByExample(mmExample);
    }

    public List<Zhuankeyaopin> findAllByXiangmuIdAndJungongyao(String xiangmuId) {
        ZhuankeyaopinExample mmExample = new ZhuankeyaopinExample();
        ZhuankeyaopinExample.Criteria criteria = mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId).andZhuankefenzuEqualTo("军供站专供");
        return ddMapper.selectByExample(mmExample);
    }


    public boolean add (Zhuankeyaopin ddZhuankeyaopin){
        return ddMapper.insert(ddZhuankeyaopin)==1;
    }

    public boolean deleteByxiangmuId(String xiangmuId){
        ZhuankeyaopinExample mmExample=new ZhuankeyaopinExample();
        ZhuankeyaopinExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.deleteByExample(mmExample)>=0;
    }

    public List<Map<String, Object>> findGuizebianhaoByXiangmuId(String ppxiangmuId){
        return ddMapper.findGuizebianhaoByXiangmuId(ppxiangmuId);
    }

    public List<Map<String, Object>> findZhuankefenzuByXiangmuId(String ppxiangmuId){
        return ddMapper.findZhuankefenzuByXiangmuId(ppxiangmuId);
    }
    public List<Map<String, Object>> findZhuankeyaopinResultByXiangmuId(String ppxiangmuId){
        return ddMapper.findZhuankeyaopinResultByXiangmuId(ppxiangmuId);
    }

    public List<Map<String, Object>> findZhuankeyaopinResult1080ByXiangmuId(String ppxiangmuId){
        return ddMapper.findZhuankeyaopinResult1080ByXiangmuId(ppxiangmuId);
    }
}
